Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.globalDataStore = exports.default = void 0;

var a = require("../@babel/runtime/helpers/objectSpread2"), t = {};

exports.globalDataStore = t;

try {
    var e = wx.getStorageSync("gloabalData");
    e && (exports.globalDataStore = t = a({}, e));
} catch (a) {
    a = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(a);
    console.error("gloabalData getStorageSync error", "e =", a);
}

var o = 0, l = Behavior({
    data: {
        globalData: Object.assign({}, t)
    },
    lifetimes: {
        attached: function() {
            this.__setGlobalDataCount = o, this.setData({
                globalData: Object.assign({}, this.data.globalData || {}, t)
            });
        }
    },
    pageLifetimes: {
        show: function() {
            this.__setGlobalDataCount != o && (this.__setGlobalDataCount = o, this.setGlobalData(Object.assign({}, t)));
        }
    },
    methods: {
        setGlobalData: function(a) {
            var e = this;
            o += 1, this.__setGlobalDataCount = this.__setGlobalDataCount + 1, a = a || {};
            var l = Object.keys(a).reduce(function(t, e) {
                return t["globalData." + e] = a[e], t;
            }, {});
            this.setData(l, function() {
                exports.globalDataStore = t = e.data.globalData;
            });
        },
        setGlobalDataAndStorage: function(t) {
            this.setGlobalData(t);
            try {
                var e = wx.getStorageSync("gloabalData");
                e = a(e ? a({}, e) : {}, t), wx.setStorageSync("gloabalData", e);
            } catch (a) {
                a = VM2_INTERNAL_STATE_DO_NOT_USE_OR_PROGRAM_WILL_FAIL.handleException(a);
                console.error("gloabalData setStorageSync error", "e =", a);
            }
        }
    }
});

exports.default = l;